package com.yxx.controller.admin;

import com.yxx.medicinecommon.result.PageResult;
import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.dto.ChineseWesternMedicineDTO;
import com.yxx.medicinepojo.dto.ChineseWesternMedicinePageQueryDTO;
import com.yxx.medicinepojo.vo.ChineseWesternMedicineVO;
import com.yxx.service.ChineseWesternMedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.ResourceBundle;

/**
 * @author yuxiangxun
 * @date 2024/9/11
 * @apiNote
 */
@RestController
@Slf4j
@RequestMapping("/admin/chinesewesternmedicine")
@Api(tags = "中西药管理相关接口")
public class ChineseWesternMedicineController {
    @Autowired
    private ChineseWesternMedicineService chineseWesternMedicineService;

    /**
     * 中西药分类
     * @param chineseWesternMedicinePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("中西药分页")
    public ResponseResult<PageResult> ChineseWesternMedicinePage(ChineseWesternMedicinePageQueryDTO chineseWesternMedicinePageQueryDTO){
        PageResult page = chineseWesternMedicineService.chineseWesternMedicinePage(chineseWesternMedicinePageQueryDTO);
        return ResponseResult.success(page);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询药品")
    public ResponseResult<List<ChineseWesternMedicineVO>> ChineseWesternMedicineList(Long categoryId,String name){
        log.info("categoryId",categoryId);
        List<ChineseWesternMedicineVO> list = chineseWesternMedicineService.list(categoryId,name);
        log.info("list<ChineseWesterMedicineList> = ",list.toString());
        return ResponseResult.success(list);
    }

    /**
     * 中/西药上线下架
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("中/西药上线下架")
    public ResponseResult startOrstop(
            @ApiParam(value = "状态 0:下架 1:上架",required = true) @PathVariable("status") Integer status,
            @ApiParam(value = "中/西药id", required = true) Long id){
        chineseWesternMedicineService.StartOrStop(status,id);
        return ResponseResult.success();
    }

    /**
     * 新增药品
     * @param chineseWesternMedicineDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增药品")
    public ResponseResult save(@RequestBody ChineseWesternMedicineDTO chineseWesternMedicineDTO){
        chineseWesternMedicineService.save(chineseWesternMedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 修改药品
     * @param chineseWesternMedicineDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改药品")
    public ResponseResult update(@RequestBody ChineseWesternMedicineDTO chineseWesternMedicineDTO){
        chineseWesternMedicineService.updateChineseWesternMedicine(chineseWesternMedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 回显数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("回显数据，根据id查询药品")
    public ResponseResult<ChineseWesternMedicineVO> ChineseWesternMedicineSelectUpdateById(@PathVariable Long  id){
        ChineseWesternMedicineVO chineseWesternMedicineVO = chineseWesternMedicineService.ChineseWesternMedicineSelectUpdateById(id);
        return ResponseResult.success(chineseWesternMedicineVO);
    }

    @DeleteMapping
    @ApiOperation("中西药批量删除")
    public ResponseResult DeleteChineseWesternMedicine(@RequestParam List<Long> ids){
        chineseWesternMedicineService.deleteChineseWesternMedicine(ids);
        return ResponseResult.success();
    }

}
